package com.czhlearn.service.impl;

import com.czhlearn.mapper.CategoryMapper;
import com.czhlearn.pojo.Category;
import com.czhlearn.pojo.Result;
import com.czhlearn.service.CategoryService;
import com.czhlearn.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @program: big-event
 * @description:
 * @author: czh
 * @create: 2023-12-19 10:33
 **/
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public void add(Category category) {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        category.setCreateUser(id);
        System.out.println(category.getCategoryName()+"---"+category.getCategoryAlias()+"==="+id);
        categoryMapper.add(category);
    }

    @Override
    public List<Category> get() {
        Map<String, Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");

        return categoryMapper.get(id);
    }

    @Override
    public Category getDetail(Integer id) {

        return categoryMapper.getDetail(id);
    }

    @Override
    public void update(Category category) {

        categoryMapper.update(category);
    }

    @Override
    public void delete(Integer id) {

        categoryMapper.delete(id);
    }
}
